package com.dk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dk.data.Result;
import com.dk.entity.DtLabel;
import com.dk.service.IDtLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("label")
@Api("增加标签")
public class LabelController {

    private IDtLabelService labelService;

    @GetMapping("selectList")
    @ResponseBody
    @ApiOperation("查询所有标签")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数",required = true,paramType = "query"),
    })
    public Result seleteList(@RequestParam(defaultValue = "1") Integer pageNum ,
                             @RequestParam(defaultValue = "5") Integer pageSize){
        IPage<DtLabel> page = labelService.selectList(pageNum, pageSize);
        return Result.ok().setData(page);
    }

    @PostMapping("insertLabel")
    @ResponseBody
    @ApiOperation("增加标签")
    public Result insertLabel(DtLabel dtLabel){
        labelService.insertLable(dtLabel);
        return Result.ok();
    }

    @PostMapping("updateLble")
    @ResponseBody
    @ApiOperation("修改标签")
    public Result updateLable(DtLabel label){
        labelService.updatgeLable(label);
        return Result.ok();
    }

    @PostMapping("selectLableById")
    @ResponseBody
    @ApiOperation("根据id查询标签")
    public Result selectLableById(Long id){
        DtLabel dtLabel = labelService.selectLableById(id);
        return Result.ok().setData(dtLabel);
    }

    @PostMapping("deleteById")
    @ResponseBody
    @ApiOperation("根据id删除标签")
    public Result deleteById(Long id){
        labelService.deleteById(id);
        return Result.ok();
    }

}
